<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="http://stripes.sourceforge.net/stripes.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%
        if (session.getAttribute("loggedIn") != null) {
            if (((Boolean) session.getAttribute("loggedIn"))) {

                if (session.getAttribute("role").equals("admin")) {
                    response.sendRedirect("managerHome.jsp");
                }
            } else {
                response.sendRedirect("index.jsp");
            }
        } else {
            response.sendRedirect("index.jsp");
        }
%>

<s:layout-render name="/layout.jsp">
    <s:layout-component name="body">
        <s:useActionBean var="actionBean" beanclass="cz.muni.fi.pa165.web.CourierShipmentActionBean" />
        <h2 style="text-align: center;" class="listHeadline"><f:message key="ManagerShipmentHeadline"/></h2>
        <table class="table table-hover">
            <tr>
                <th>ID</th>
                <th><f:message key="Manager-Shipment-list-sender"/></th>
                <th><f:message key="Manager-Shipment-list-recipient"/></th>
                <th><f:message key="Manager-Shipment-list-shipmentState"/></th>
                <th><f:message key="Manager-Customer-list-edit"/></th>
            </tr>
            <c:forEach items="${actionBean.shipments}" var="shipment">
                <tr>
                    <td><c:out value="${shipment.id}"/></td>
                    <td><c:out value="${shipment.sender.firstName}"/> <c:out value="${shipment.sender.lastName}"/></td>
                    <td><c:out value="${shipment.recipient.firstName}"/> <c:out value="${shipment.recipient.lastName}"/></td>
                    <td><c:out value="${shipment.shipmentState}"/></td>
                    <td><s:link class="btn btn-small" beanclass="cz.muni.fi.pa165.web.CourierShipmentActionBean" event="edit" href="/editCourierShipments.jsp">
                            <s:param name="shipment.id" value="${shipment.id}"/>
                            <f:message key="Manager-Customer-list-edit"/>
                        </s:link>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </s:layout-component>
</s:layout-render>
